﻿/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_CRYPTO_SHA1_H_
#define SHARED_CRYPTO_SHA1_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <cstdint>
#include <openssl/sha.h>
#include <openssl/crypto.h>
#include "Shared/Global_Macros.h"


namespace Shared {
namespace Crypto {
    class BigNumber;

    class Sha1Hash
    {
    public:
        Sha1Hash(void);
        ~Sha1Hash(void);

    public:
        void initialize(void);
        void finalize(void);

        void updateBigNumbers(BigNumber*, ...);
        void updateData(const std::uint8_t*, std::size_t);
        void updateData(const std::string&);

        const std::uint8_t* digest(void) const { return &_digest[0]; }
        int length(void) const { return SHA_DIGEST_LENGTH; }

    private:
        SHA_CTX         _ctx;
        std::uint8_t    _digest[SHA_DIGEST_LENGTH];

        DISALLOW_COPY_AND_ASSIGN(Sha1Hash);
    };

}}

#endif // SHARED_CRYPTO_SHA1_H_
